package com.cj.designpattern.strategy.impl;

import com.cj.designpattern.strategy.ICalculateStrategy;

/**
 * ClassName: BusStrategy <br/>
 * Function: 公交车价格计算策略 <br/>
 * date: 2018/04/28 14:26 <br/>
 *
 * @author chenj
 * @version 1.0.0
 * @since JDK 1.8
 */
public class BusStrategy implements ICalculateStrategy {

    @Override
    public int calculatePrice(int km) {
        int extraTotal = km - 10;
        int extraFactor = extraTotal / 5;
        int fraction = extraTotal % 5;
        int price = 1 + extraFactor * 1;
        int priceResult = fraction > 0 ? ++price : price;
        System.out.println("做公交车" + km + "公里，价格为：" + priceResult + "元");
        return priceResult;
    }
}
